package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ContractFileDao;
import cn.topevery.garden.entity.po.ContractFile;
import cn.topevery.garden.entity.query.ContractFileQuery;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-06
 */
@Service
public class ContractFileLogic extends BaseLogic<ContractFile> {
    @Autowired
    ContractFileDao contractFileDao;

    @Override
    public BaseEntityDao<ContractFile, Integer> getDao() {
        return contractFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ContractFile> listPage(ContractFileQuery query) {
        return contractFileDao.listPage(query);
    }

    public List<ContractFile> getListByPid(Integer pid){
        return contractFileDao.getListByPid(pid);
    }

    public  boolean saveOrUpdate(String userId,Integer pId, List<ContractFile> contractFileList){
        contractFileDao.deleteById(pId);
        for(ContractFile contractFile: contractFileList){
            contractFile.setMainId(pId);
            contractFileDao.saveOrUpdate(userId, contractFile);
        }
        return true;
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        contractFileDao.delete(userId, ids);
    }
}
